function [ia_network, status, s1Targets, s2Targets] = IA_ScheduleInit(sensor1TargetOrder, sensor2TargetOrder)
%IA_ScheduleInit Summary of this function goes here
% Detailed explanation goes here
status = 0;

s1rows = size(sensor1TargetOrder, 1);
s1cols = size(sensor1TargetOrder, 2);
s2rows = size(sensor2TargetOrder, 1);
s2cols = size(sensor2TargetOrder, 2);

% Get ordered list of sensor 1 targets
[s1NumTargets, s1Targets] = ST_OrderedTargetList(sensor1TargetOrder);

% Get ordered list of sensor 2 targets
[s2NumTargets, s2Targets] = ST_OrderedTargetList(sensor2TargetOrder);

% Create the intervals and relations
s1Intervals(1:s1rows, 1:s1cols) = IA_Interval('', -1);
s2Intervals(1:s2rows, 1:s2cols) = IA_Interval('', -1);

i = 1;
for r = 1:s1rows
  for c = 1:s1cols
    if sensor1TargetOrder(r, c) > 0
      s1Intervals(r, c) = IA_Interval(sprintf('S1_T%i', i), s1Targets(i));
      i = i + 1;
    end
  end
end

i = 1;
for r = 1:s2rows
  for c = 1:s2cols
    if sensor2TargetOrder(r, c) > 0
      s2Intervals(r, c) = IA_Interval(sprintf('S1_T%i', i), s2Targets(i));
      i = i + 1;
    end
  end
end

ia_network = IA_Network_Empty();

temp_n1 = [];
n1 = [];
n2 = 1;
k = 1;
for r = 1:s1rows
  for c = 1:s1cols
    if ~strcmp(s1Intervals(r, c).name, '')
      ia_network = IA_Network_Add_Interval(ia_network, s1Intervals(r, c));
      if (IA_Network_Nodes(ia_network) > 1) && (r > 1)
        for i = 1:size(n1, 2)
          [ia_network, consistent] = IA_Network_Path_Consistency(...
            ia_network, n1(i), n2, IA_Relation_Less());
          if ~consistent
            % error in algorithm, should not happen if logic above is ok.
            return;
          end
        end
      end
      temp_n1(k) = n2; %#ok<AGROW>
      k = k + 1;
      n2 = n2 + 1;
    end
  end
  n1 = temp_n1;
  temp_n1 = [];
  k = 1;
end

temp_n1 = [];
n1 = [];
k = 1;
for r = 1:s2rows
  for c = 1:s2cols
    if ~strcmp(s2Intervals(r, c).name, '')
      ia_network = IA_Network_Add_Interval(ia_network, s2Intervals(r, c));
      if (IA_Network_Nodes(ia_network) > 1) && (r > 1)
        for i = 1:size(n1, 2)
          [ia_network, consistent] = IA_Network_Path_Consistency(...
            ia_network, n1(i), n2, IA_Relation_Less());
          if ~consistent
            % error in algorithm, should not happen if logic above is ok.
            return;
          end
        end
      end
      temp_n1(k) = n2; %#ok<AGROW>
      k = k + 1;
      n2 = n2 + 1;
    end
  end
  n1 = temp_n1;
  temp_n1 = [];
  k = 1;
end
status = 1;
end